package com.project.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.project.db.SQLHelper;
import com.project.model.FactoryResume;
import com.project.model.FactoryResumeA;
import com.project.model.FactoryResumeC;
import com.project.model.Resume;
import com.project.model.ResumeC;

/**
 * Servlet implementation class SubmitResume
 */
@WebServlet("/SubmitResume")
public class SubmitResume extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SubmitResume() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Cookie[] cookie = request.getCookies();
		String userid = "";
		for (Cookie c : cookie) {
			if (c.getName().equals("userid")) {
				userid = c.getValue();
			}
		}
		String name = request.getParameter("name");
		String age = request.getParameter("age");
		String sex = request.getParameter("sex");
		String school = request.getParameter("college");
		String subject = request.getParameter("subject");
		String phone = request.getParameter("phone");
		String email = request.getParameter("email");
		String textarea = request.getParameter("textarea");
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String createtime = df.format(new Date());
		String edittime = df.format(new Date());

		ResumeC resume = new ResumeC();
		resume.setUser_id(new Integer(userid));
		resume.setName(name);
		resume.setAge(new Integer(age));
		resume.setSex(sex);
		resume.setSchool(school);
		resume.setSubject(subject);
		resume.setPhone(phone);
		resume.setEmail(email);
		resume.setDescription(textarea);
		resume.setCreatetime(createtime);
		resume.setEdittime(edittime);
		int result = 0;
		try {
			result = SQLHelper.addResume(resume);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.getWriter().print(result);
	}
}
